home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / CrashBurn.sit / Crash & Burn / source code / FireBug.cpp < prev    next >
C/C++ Source or Header  |  1997-06-27  |  7KB  |  339 lines

  1. #include "patches.h"
  2. #include <traps.h>
  3. #include <lowmem.h>
  4.  
  5. #include <iostream>
  6. #include <qdoffscreen.h>
  7. #include "RectUtilities.h"
  8. #include "flames.h"
  9.  
  10. static asm long*    GetOldDebugUtilStorage()
  11. {
  12.     lea        _oldDebugUtilStorage,a0
  13.     rts
  14. _oldDebugUtilStorage:
  15.     dc.l    0x00000000
  16. }
  17.  
  18. static asm long* GetCountStorage()
  19. {
  20.     lea        _countStorage,a0
  21.     rts
  22. _countStorage:
  23.     dc.l    0x00000000
  24. }
  25.  
  26.  
  27. static asm long* GetValueStorage()
  28. {
  29.     lea        _valueStorage,a0
  30.     rts
  31. _valueStorage:
  32.     dc.l    0x00000000
  33. }
  34.  
  35.  
  36.  
  37. static asm long* GetA5Storage()
  38. {
  39.     lea        _a5Storage,a0
  40.     rts
  41. _a5Storage:
  42.     dc.l    0x00000000
  43. }
  44.  
  45.  
  46.  
  47. static Boolean        KeyIsDown(
  48.     short            theKeyCode)
  49. {
  50.     KeyMap            theKeys;
  51.     
  52.     GetKeys( theKeys);                    /* Get state of each key            */
  53.                                         
  54.         /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a    */
  55.         /* 16-byte (128 bits) array where each bit specifies the start    */
  56.         /* of a key (0 = up, 1 = down). We isolate the bit for the        */
  57.         /* specified key code by first determining the byte position in    */
  58.         /* the KeyMap and then the bit position within that byte.        */
  59.         /* Key codes 0-7 are in the first byte (offset 0 from the        */
  60.         /* start), codes 8-15 are in the second, etc. The BitTst() trap    */
  61.         /* counts bits starting from the high-order bit of the byte.    */
  62.         /* For example, for key code 58 (the option key), we look at    */
  63.         /* the 8th byte (7 offset from the first byte) and the 5th bit    */
  64.         /* within that byte.                                            */
  65.         
  66.     return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
  67.                     (long) 7 - (theKeyCode % 8) ) );
  68. }
  69.  
  70. // 16777216
  71.  
  72. static void memset(Ptr p,char value,long length)
  73. {
  74.     long    z = 0;
  75.     for(z = 0;z<length;z++){
  76.         p[z] = value;
  77.     }
  78. }
  79.  
  80. static    Ptr GetScreenBase()
  81. {
  82.     GDHandle        h = LMGetMainDevice();
  83.     
  84.     return h[0]->gdPMap[0]->baseAddr;
  85. }
  86.  
  87. static     CGrafPort    gMyPort;
  88. static  FlameDataRecPtr    gFlames = NULL;
  89. static long    Poll(short selector)
  90. {
  91.     long        continueQ = true;
  92.     long*        myA5 = GetA5Storage();
  93.     
  94.     SetA5(*myA5);
  95.     
  96.     long*        count = GetCountStorage();
  97.     
  98.     if(selector == 3){
  99.         (*count)++;
  100.         
  101.         if( ((*count) % 150) == 0){
  102.  
  103.             if(gFlames)
  104.                 StepFlames(gFlames);
  105.  
  106.         }
  107.     }
  108.     
  109.     return continueQ;
  110. }
  111.  
  112.  
  113. static asm void newDebugUtil()
  114. {
  115.     subq.l    #4,a7                        // reserve space for old trap address
  116.     move.l    a0,-(a7)                    // save a0
  117.     movem.l    a1-a5/d0-d7,-(a7)            // save everything else
  118.     
  119.     move.w    d0,-(a7)
  120.     jsr        Poll
  121.     addq.l    #2,a7
  122.     tst.w    d0
  123.     bne.s    _Continue
  124.     
  125.     movem.l    (a7)+,a1-a5/d0-d7
  126.     move.l    (a7)+,a0
  127.     addq.l    #4,a7
  128.     rts
  129.     
  130. _Continue:
  131.     
  132.  
  133.     movem.l    (a7)+,a1-a5/d0-d7            // restore registers
  134.     
  135.     jsr        GetOldDebugUtilStorage        // get original trap address storage in a0
  136.     move.l    (a0),a0                        // get original trap address value into a0
  137.     move.l    a0,4(a7)                    // stuff old trap onto stack
  138.     move.l    (a7)+,a0                    // restore original a0
  139.     rts                                    // rts to jump to old trap.
  140. }
  141.  
  142. static void LockHandle(Handle    h)
  143. {
  144.     if(h){
  145.         HLock(h);
  146.     }
  147. }
  148.  
  149. static void UnlockHandle(Handle h)
  150. {
  151.     if(h){
  152.         HUnlock(h);
  153.     }
  154. }
  155.  
  156. static void    UnlockPixMap(PixMapHandle p)
  157. {
  158.     if(p){
  159.         UnlockHandle((Handle)p);
  160.         UnlockHandle((Handle)p[0]->pmTable);
  161.     }
  162. }
  163.  
  164. static void    LockPixMap(PixMapHandle    p)
  165. {
  166.     if(p){
  167.         LockHandle((Handle)p);
  168.         LockHandle((Handle)p[0]->pmTable);
  169.     }
  170. }
  171.  
  172. static void    LockPixPat(PixPatHandle p)
  173. {
  174.     if(p){
  175.         LockHandle((Handle)p);
  176.         LockPixMap(p[0]->patMap);
  177.         LockHandle((Handle)p[0]->patData);
  178.         LockHandle((Handle)p[0]->patXData);
  179.         LockHandle((Handle)p[0]->patXMap);
  180.     }
  181. }
  182.  
  183. void main()
  184. {
  185.     cout << "Init" << endl;
  186.     
  187.     GDHandle    mainDevice = GetMainDevice();
  188.     
  189.     LockHandle((Handle)mainDevice);
  190.     LockPixMap(mainDevice[0]->gdPMap);
  191.     LockHandle((Handle)mainDevice[0]->gdITable);
  192.     LockHandle((Handle)mainDevice[0]->gdSearchProc);
  193.     LockHandle((Handle)mainDevice[0]->gdCompProc);
  194.  
  195.     
  196.     OpenCPort(&gMyPort);
  197.     SetPort((GrafPtr)&gMyPort);
  198.     BackColor(blackColor);
  199.     EraseRect(&gMyPort.portRect);
  200.     BackColor(whiteColor);
  201.     
  202.     Rect            macsBug;
  203.     Rect            screenRect;
  204.     SetRect(&macsBug,0,0,640,480);
  205.     SetRect(&screenRect,0,0,0x340,624);
  206.     Point            center;
  207.     
  208.     center.h = screenRect.right/2;
  209.     center.v = screenRect.bottom/2;
  210.     
  211.     RectUtil::CenterRectOnPoint(&macsBug,center);
  212.     RgnHandle        screenRgn = NewRgn();
  213.     RgnHandle        mbRgn = NewRgn();
  214.     
  215.     RectRgn(screenRgn,&screenRect);
  216.     RectRgn(mbRgn,&macsBug);
  217.     
  218.     DiffRgn(screenRgn,mbRgn,screenRgn);
  219.     
  220.     SetClip(screenRgn);
  221.  
  222.     
  223.     LockPixMap(gMyPort.portPixMap);
  224.     LockHandle((Handle)gMyPort.grafVars);
  225.     LockHandle((Handle)gMyPort.visRgn);
  226.     LockHandle((Handle)gMyPort.clipRgn);
  227.     LockPixPat(gMyPort.bkPixPat);
  228.     LockPixPat(gMyPort.pnPixPat);
  229.     LockPixPat(gMyPort.fillPixPat);
  230.  
  231.  
  232.                     double    fFadeRate = 0.04;
  233.                     double    fDensity = 0.5;    
  234.                     short    fMinWidth = 2;
  235.                     short    fMaxWidth = 4;                
  236.     
  237.     FlameDataRecPtr        f;
  238.  
  239.     
  240.     Rect                myRect;
  241.     
  242.     myRect = macsBug;
  243.     myRect.bottom = myRect.top;
  244.     myRect.top -= 75;
  245.     myRect.left += 100;
  246.     myRect.right -= 100;
  247.     
  248. //    myRect.top = myRect.bottom - 50;
  249. //    myRect.right = myRect.left + 150;
  250. //    myRect.top = myRect.bottom - 100;
  251. //    myRect.left += 200;
  252. //    myRect.right -= 200;
  253.     
  254.     f = MakeNewFlames ((GrafPtr)&gMyPort, &myRect,
  255.                                 fMinWidth,fMaxWidth,
  256.                                 fDensity, fFadeRate, 
  257.                                 30,GetCTable(1280));
  258.  
  259.     LockFlames(f);
  260.     StartFlames (f);
  261.  
  262.     gFlames = f;
  263.  
  264.  
  265.         long*        a5Storage = GetA5Storage();
  266.         *a5Storage = SetCurrentA5();
  267.         
  268.         long*        debugUtilStorage = GetOldDebugUtilStorage();
  269.         *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
  270.  
  271.  
  272.         Debugger();
  273.  
  274.  
  275.     
  276.     FreeFlames(&f);
  277.  
  278.     CloseCPort(&gMyPort);
  279.  
  280.  
  281.     UnlockHandle((Handle)mainDevice[0]->gdCompProc);
  282.     UnlockHandle((Handle)mainDevice[0]->gdSearchProc);
  283.     UnlockHandle((Handle)mainDevice[0]->gdITable);
  284.     UnlockPixMap(mainDevice[0]->gdPMap);
  285.     UnlockHandle((Handle)mainDevice);
  286.     
  287. }
  288.  
  289. /*
  290. void main()
  291. {
  292.     cout << "init" << endl;
  293.     
  294.     GWorldPtr    myGWorld;
  295.     Rect        myBounds;
  296.     SetRect(&myBounds,0,0,0x340,624);
  297.     OSErr    err = NewGWorld(&myGWorld, 8, &myBounds, NULL,NULL, 0);
  298.     if(err == noErr){
  299.         LockPixels(GetGWorldPixMap(myGWorld));
  300.         HLock((Handle)GetGWorldPixMap(myGWorld));
  301.         
  302.     //    long*        a5Storage = GetA5Storage();
  303.     //    *a5Storage = SetCurrentA5();
  304.         
  305.     //    long*        debugUtilStorage = GetOldDebugUtilStorage();
  306.     //    *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
  307.         
  308.         DPGlobals*    dpGlobals = GetDPGlobalStorage();
  309.         InitDPGlobals(dpGlobals);
  310.             Ptr        screenBase = GetScreenBase();
  311.             long*    value = GetValueStorage();
  312.             
  313.             dpGlobals->gDPAddress = GetGWorldPixMap(myGWorld)[0]->baseAddr;
  314.             dpGlobals->gDPBytesPerRow = GetGWorldPixMap(myGWorld)[0]->rowBytes;
  315.             dpGlobals->gDPHeight = 624;
  316.             dpGlobals->gDPWidth = 0x0340;
  317.             dpGlobals->gDPDepth = 8;
  318.             
  319.             const    UInt32    kScreenWidth = 0x0340;
  320.             const    UInt32    kScreenHeight = 624;
  321.     
  322.             *value = !(*value);
  323.             DPFilledRect (dpGlobals,0, 0, kScreenWidth, kScreenHeight, (*value)?0:0xFF);
  324.             CopyBits((BitMap*)*GetGWorldPixMap(myGWorld), (BitMap*)*GetMainDevice()[0]->gdPMap, &myBounds, &myBounds, 0,NULL);
  325.             
  326.             Debugger();
  327.         //    *value = !(*value);
  328.         //    DPMoveTo(dpGlobals,0,0);
  329.         //    DPLineTo(dpGlobals,400,0,1);
  330.         //    Debugger();
  331.         //    DPMoveTo(dpGlobals,0,0);
  332.         //    DPLineTo(dpGlobals,400,0,50);
  333.         //    Debugger();
  334.     //    Debugger();
  335.     }
  336.  
  337. }
  338.  
  339. */